package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mobile.domain.UserPrescription;
import com.ruoyi.mobile.model.bo.UserPrescriptionInfoBo;
import com.ruoyi.mobile.model.request.UserPrescriptionRequest;
import com.ruoyi.mobile.model.vo.UserPrescriptionVo;
import com.ruoyi.mobile.service.IUserPrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户运动处方
 * 
 * @author ruoyi
 * @date 2022-10-03
 */
@RestController
@RequestMapping("/mobile/userprescription")
public class UserPrescriptionController extends BaseController
{

    @Autowired
    private IUserPrescriptionService userPrescriptionService;

    /**
     * 查询用户运动处方列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:userprescription:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPrescription userPrescription)
    {
        startPage();
        List<UserPrescriptionInfoBo> list = userPrescriptionService.selectUserPrescriptionList(userPrescription);
        return getDataTable(list);
    }


    /**
     * 获取用户运动处方详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:userprescription:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        UserPrescriptionVo userPrescriptionVo = userPrescriptionService.selectUserPrescriptionById(id);
        return AjaxResult.success(userPrescriptionVo);
    }

    /**
     * 新增用户运动处方
     */
    @PreAuthorize("@ss.hasPermi('mobile:userprescription:add')")
    @Log(title = "推荐课程记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPrescriptionRequest userPrescriptionRequest)
    {
        return toAjax(userPrescriptionService.insertUserPrescription(userPrescriptionRequest));
    }

    /**
     * 修改用户运动处方
     */
    @PreAuthorize("@ss.hasPermi('mobile:userprescription:edit')")
    @Log(title = "推荐课程记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPrescriptionRequest userPrescriptionRequest)
    {
        return toAjax(userPrescriptionService.updateUserPrescription(userPrescriptionRequest));
    }

    /**
     * 删除用户运动处方
     */
    @PreAuthorize("@ss.hasPermi('mobile:userprescription:remove')")
    @Log(title = "推荐课程记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(userPrescriptionService.deleteUserPrescriptionByIds(ids));
    }
}
